using System;
using System.Collections.Generic;
using System.Text;

namespace Bots
{
    /// <summary>
    /// Period task
    /// </summary>
    public class TimeIntervalScheduler : Scheduler
    {
        private DateTime startTime = DateTime.Now;
        private long interval = 500;

        protected override bool IsRunable()
        {
            TimeSpan timeSpan = DateTime.Now.Subtract(this.startTime);
            bool isRun = (timeSpan.TotalMilliseconds >= interval);
            if(isRun)
                this.startTime = DateTime.Now;
            return isRun;
        }

        protected TimeIntervalScheduler() { }

        public TimeIntervalScheduler(ITask task)
        {
            this.task = task;
        }

        public TimeIntervalScheduler(ITask task, int intervalTime)
        {
            this.task = task;
            this.interval = intervalTime;
        }
    }
}
